function [n] = bestgrid(x)

n = [0 0];


% first see if x is a nice squareed value, use that if possible.
s = sqrt(x);
if(rem(s, floor(s)) == 0)
   n = [s s]; 
   return;
end;
possy = floor(s); % try closest integer to root
% allfactors  -  compute all the possible integer factors of x
% note that this is a grunge method...
% find all the factors
f=[];
for i = 1:x
   if(rem(x, i) == 0)
      f = [f i];
   end;
end;
[px, possx] = find(possy == f);
if(~isempty(possx))
   n = [x/f(possx) possy];
   return;
end;

return;
